﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace ConjureBivouac2012.Object
{
    public class ShuffleBullet : AbstractBullet
    {
        public ShuffleBullet()
            : base(20, 300)
        {
            base.Initialize();
            lastTime = new TimeSpan();
            animationCount = 0;
            animationDelay = 100;
            LoadContent(GameInfo.GetInstance().GetContent());
            timeLife = 15;
            this.myName = NBULLET;
            this.vulnerableTo = PLAYER;
            contentName = "Bullet/ShuffleBullet";
        }

        public override void Fire(Entity owner, Vector2 theDirection)
        {
            theDirection.Normalize();
            this.sprite.Position = owner.sprite.Position + theDirection * (owner.GetRadius() + this.GetRadius() + 2);
            this.SetDirection(theDirection);
            this.setVelocity(new Vector2(_speed, _speed));
            base.Visible = true;
        }

        public override bool canCollide()
        {
            myName = BBULLET;
            vulnerableTo = "ENNEMY";
            contentName = "Bullet/GBullet";
            return false;
        }

        public override void LoadContent(ContentManager contentManager)
        {
            base.LoadContent(contentManager);
        }

        public override void Update(GameTime time)
        {
            if (time.TotalGameTime.TotalMilliseconds - lastTime.TotalMilliseconds > animationDelay)
            {
                animationCount++;
                this.sprite.LoadContent(GameInfo.GetInstance().GetContent(), contentName + animationCount);
                animationCount %= 2;
                lastTime = time.TotalGameTime;
            }

            base.Update(time);
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (Visible)
            {
                base.Draw(spriteBatch);
            }
        }
    }
}
